Skip to content

[SoftCSA] Threaded CW delivery and softcam reliability fixes#3698

Merged
jbleyel merged 7 commits intoopenatv:masterfrom
WXbet:softcsa-threading
Feb 8, 2026
Merged

[SoftCSA] Threaded CW delivery and softcam reliability fixes#3698
jbleyel merged 7 commits intoopenatv:masterfrom
WXbet:softcsa-threading

Conversation

@WXbet
Copy link
Contributor

@WXbet WXbet commented Feb 8, 2026

  • Decouple CW delivery from MainLoop: New eDVBCWHandler runs a dedicated thread with a socketpair proxy between the softcam and ePMTClient. CW keys are delivered via setKey() even when the MainLoop is blocked (e.g. during spinner/service switch)

  • Fix SR→Live switching delay: When switching from StreamRelay to Live-TV on the same service, send CMD_NOT_SELECTED + LIST_ADD to force the softcam to resend the current CW immediately instead of waiting for the next ECM cycle.

  • Fix broken descrambling after standby/zapping: Keep softcam client connections alive across service gaps. The CWHandler proxy masks socket disconnects from the softcam, so the previous teardown in serviceGone() left the softcam unaware and unable to reconnect.

  • Fix CI module vs SoftCSA conflict: Deactivate software descrambling when recheckPMTHandlers() assigns a CI slot, preventing the SoftCSA icon from showing incorrectly and the SoftDecoder from running alongside hardware descrambling.

  • Buffer CW during activation race: When a CW arrives before the CSA session activates, buffer it and replay on activation, handling the ~50-250ms race window at channel start.

  • Fix protocol corruption on zap: Zero-initialize m_capmt and skip uninitialized services in distributeCAPMT(), preventing stale heap data from corrupting the DVBAPI protocol stream.

WXbet added 7 commits February 8, 2026 13:58
Add eDVBCWHandler that sits between the softcam socket and ePMTClient:
- Takes ownership of the softcam fd, creates a socketpair for ePMTClient
- Runs a dedicated poll() thread independent of the MainLoop
- Intercepts CA_SET_DESCR packets and calls setKey() directly
- Forwards ALL data bidirectionally so ePMTClient works unchanged

This ensures CW delivery continues even when the MainLoop is blocked
(spinner). The MainLoop still receives all packets for signal handling
(firstCwReceived, ECM_INFO, etc.), but setKey() is ONLY called from
the eDVBCWHandler thread.

Also suppress false stream-stall detections after MainLoop hangs:
the SoftDecoder health timer cannot fire during a freeze, so on resume
it would falsely trigger pause/play recovery. Now detects timer gaps
>2s and skips the stall check, avoiding unnecessary audio/video glitches.

Reduce log spam: CW set and ECM Mode messages only log on first CW or
when values actually change, instead of every ~7 seconds.

Changes:
- New: cwhandler.h/cpp - eDVBCWHandler socketpair proxy with CW interception
- cahandler: Route softcam connections through eDVBCWHandler, add serviceId
  to receivedCw signal
- csasession: Register engine with eDVBCWHandler instead of calling setKey(),
  unregister on deactivation/destruction
- servicedvbsoftdecoder: Skip stall-detection after MainLoop freeze
Align log tags with actual class names:
- [CSASession] -> [eDVBCSASession]
- [CSAEngine] -> [eDVBCSAEngine]
- [SoftDecoder] -> [eDVBSoftDecoder]
When a CW arrives from OSCam before ECM analysis completes and the
CSA session activates, the CW is buffered (PendingCw) and replayed
immediately upon activation. This handles the race condition where the
CW arrives ~50-250ms before the session is ready.
When switching from StreamRelay to Live-TV for the same service, the
softcam's demux is already running and a simple LIST_UPDATE causes it
to just "continue processing" without resending the current CW. The
new CSA session has no keys and must wait for the next ECM cycle (~4-8s).

Fix: Send CMD_NOT_SELECTED first to stop the demux, then LIST_ADD with
CMD_OK_DESCRAMBLING to restart it. This forces the softcam to treat the
service as new and immediately send the current CW.
…ryption

When a service uses CSA-ALT and the ECM cache has a hit, the CSA session
activates speculatively via startECMMonitor() during eventNewProgramInfo.
However, recheckPMTHandlers() runs AFTER this event and may assign a CI
slot for hardware descrambling. This caused the SoftCSA icon to show
incorrectly and the SoftDecoder to run unnecessarily alongside the CI module.

Add eventCIConnected to eDVBServicePMTHandler, fired after recheckPMTHandlers()
assigns a CI slot. eDVBServicePlay handles this event by stopping the ECM
monitor and deactivating the CSA session, which triggers onSessionActivated(false)
to stop the SoftDecoder and restore the hardware decoder.
distributeCAPMT() was sending CAPMT objects for services that had been
registered but never received their PMT. Since m_capmt[2048] was not
initialized in the eDVBCAService constructor, this resulted in stale
heap data (typically recycled EIT/EPG section data) being sent over
the socket, corrupting the DVBAPI protocol stream.

This caused "Unknown socket command received" and "network packet
malformed" errors in OSCam when zapping between channels (particularly
BISS channels on Abertis 30W where active EPG data fills the heap).

Fix: Skip services with m_version == -1 (buildCAPMT never called) in
distributeCAPMT(), and zero-initialize m_capmt in the constructor.
…oder

When switching between SoftCSA channels, the skin was notified via
evUpdatedInfo immediately after SoftDecoder takeover. At that point the
SoftDecoder's hardware decoder does not exist yet (it is created only
after the first CW arrives), so getVideoHeight() returns -1. The skin
falls back to eAVControl which reads /proc/stb/vmpeg/0/yres from the
just-released HW decoder, returning 0. This causes the HD icon to grey
out. On platforms where VIDEO_EVENT_SIZE_CHANGED is suppressed for
identical resolutions (e.g. VU Solo4K), the icon never recovers.

Add a m_decoder_ready signal to eDVBSoftDecoder, fired after the decoder
reaches PLAY state. eDVBServicePlay defers the evUpdatedInfo notification
until this signal arrives, ensuring the skin queries valid video info.
@jbleyel jbleyel merged commit f4de2c2 into openatv:master Feb 8, 2026
3 of 4 checks passed
@WXbet WXbet deleted the softcsa-threading branch February 8, 2026 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants